<?php
declare(strict_types=1);

namespace App\Controller\Api\V1\Common;

use App\Controller\Api\BaseController;
use App\Repositories\AreaRepository;
use App\Repositories\CommunityRepository;
use App\Repositories\StreetRepository;

class AreaController extends BaseController
{
    public function all()
    {
        $parent_id = $this->request->input('parent_id',0);
        $where=[
            'parent_id'=>[
                'field' => 'parent_id',
                'value' => $parent_id
            ]
        ];
        $order = [
            [
                'field' => 'listorder',
                'sort' => 'asc'
            ]
        ];
        $return= AreaRepository::getInstance()->all(['id','name','parent_id'],$where,$order);
        return $this->response->success($return);
    }

    public function street(){
        $district_id = $this->request->input('district_id',0);
        $where=[
            'parent_id'=>[
                'field' => 'district_id',
                'value' => $district_id
            ]
        ];
        $return= StreetRepository::getInstance()->all(['id','name','district_id'],$where);
        return $this->response->success($return);
    }

    public function community(){
        $street_id = $this->request->input('street_id',0);
        $where=[
            'parent_id'=>[
                'field' => 'street_id',
                'value' => $street_id
            ]
        ];
        $return= CommunityRepository::getInstance()->all(['id','name','street_id'],$where);
        return $this->response->success($return);
    }
}